package com.fallsvc.chatroom.controller;

import com.fallsvc.chatroom.common.Constants;
import com.fallsvc.chatroom.mapper.FriendMapper;
import com.fallsvc.chatroom.model.Friend;
import com.fallsvc.chatroom.model.User;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @auther falls_vc
 * description:
 * @date 2025/4/27  19:53
 */
@Slf4j
@RestController

public class FriendController {

    @Resource
    private FriendMapper friendMapper;
    @RequestMapping("/friendList")
    public Object getFriendList(HttpServletRequest request){
        // 1.获得会话 获得userId
        HttpSession session=request.getSession(false);
        if(session==null){
            log.info("[getFriendList] 用户未登陆 ");
            return new ArrayList<Friend>();
        }
        User user=(User) session.getAttribute(Constants.USER);
        if(user==null){
            log.info("[getFriendList] 用户不存在");
            return new ArrayList<Friend>();
        }
        // 2. 查找好友
        List<Friend> list=friendMapper.selectFriendList(user.getUserId());
        log.info("获得好友列表成功，list:{}",list);
        return list;
    }
}
